<?xml version="1.0" encoding="UTF-8"?>
<!-- Convert INEX submissions (2005 format) into SQL statements -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="text"/>

    <xsl:param name="submissionid">0</xsl:param>
    <xsl:template match="inex-submission">insert into submission(id, participant, name) values(<xsl:value-of select="$submissionid"/>, <xsl:value-of select="@participant-id"/>, '<xsl:value-of select="@run-id"/>');
        <xsl:apply-templates select="topic"/>
    </xsl:template>
    <xsl:template match="topic">
        start transaction;
        <xsl:apply-templates select="result"/>
        commit;
    </xsl:template>
    <xsl:template match="result">
        insert into result(topic, rank, submissionid, fragmentid) values(<xsl:value-of select="../@topic-id"/>, <xsl:value-of select="count(preceding-sibling::result)+1"/>, <xsl:value-of select="$submissionid"/>, (select f.id from fragment f, document d, xpath x where f.docid = d.id and f.xpathid = x.id and x.xpath ='<xsl:value-of select="path"/>' and d.name='<xsl:value-of select="file"/>'));
    </xsl:template>
</xsl:stylesheet>
